#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    modbusMaster = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1);
    modbus_set_slave(modbusMaster, 0x01);
    if(modbus_connect(modbusMaster) != -1)
    {
      modbus_set_response_timeout(modbusMaster, 0, 500000);
      qDebug() << "The modbus connect success!";
    }
    receiverData();
}

MainWindow::~MainWindow()
{
    delete ui;
}

int MainWindow::receiverData()
{
    uint16_t data;
    int resultKey = modbus_read_registers(modbusMaster, 0x20,1,&data);
    if(resultKey != -1)
    {
        qDebug() << data;
    }
    return 1;
}
